﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace VRacer.Packets
{
    public class PlayerMovedPacket : PlayerPacket
    {
        private int _newX;
        private int _newY;

        public PlayerMovedPacket()
            : base(PacketType.PlayerMoved)
        {
            this.Length += 12;
        }

        public PlayerMovedPacket(PlayerBase player, Point newPosition)
            : this()
        {
            this.ID = player.ID;
            this.NewPosition = newPosition;
        }

        public Point NewPosition
        {
            get { return new Point(_newX, _newY); }
            set
            {
                _newX = (int)value.X;
                _newY = (int)value.Y;
            }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _id = reader.ReadInt32();
            _newX = reader.ReadInt32();
            _newY = reader.ReadInt32();
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.Write(_id);
            writer.Write(_newX);
            writer.Write(_newY);
        }
    }
}
